import $ from 'jquery';
import styles from './main.css';//导入


class Article {
    constructor() {
        this.upId = null;
        this.upName = null;
        this.time = null;
        this._init();
    }

    _init() {
        let elArticleUp = document.getElementById('article-up');
        let elUpName = elArticleUp.querySelector('.up-name  a');
        this.upName = elUpName.innerHTML;

        let href = elUpName.getAttribute('href');
        this.upId = href.replace('/u/', '').replace('.aspx', '');

        let elTime = elArticleUp.querySelector('.up-time');
        this.time = elTime.innerHTML;
    }

    // 高亮楼主名字
    highlightUp() {
        let COLOR = "#008000";
        let highlightUpStyle = document.createElement('style');
        highlightUpStyle.innerHTML = `
        a[data-uid="${this.upId}"]
            {
                color: ${COLOR} !important;
                font-weight: bold !important;
            }
        `;
        document.head.appendChild(highlightUpStyle);
    }

    // 在查看下一页评论时，文章内容也一直显示
    alwaysShowContent(){
        $('#article-content').addClass('display-block');
    }

    // 让评论区域居中显示
    centerComments(){
        let elComment = $('.comment-area  .columen-left:first');
        elComment.addClass('comment-content');
        elComment.removeClass('fl');
    }

    // 评论区域元素上移
    moveUpComments(){
        let elCommentArea = $('.comment-area:first');
        let elCommentAreaParent = elCommentArea.parent();
        elCommentArea.remove();
        elCommentAreaParent.parent().append(elCommentArea);
    }

}

let article = new Article();
article.highlightUp();
article.alwaysShowContent();
article.centerComments();
article.moveUpComments();